<?php

/**
 * @author dungdhs@gmail.com
 * @copyright 2012
 */

function __blog_get($blog_id=0){
  global $database;
  
  $res = $database->db_query("SELECT * FROM blogs WHERE blog_id=%d LIMIT 1", $blog_id);
  
  if ($blog = $database->db_fetch_assoc($res)){
    $aCat = __blog_category($blog_id, 1);
    $blog['blog_cat'] = array_pop($aCat);
    $blog['blog_ultis'] = __blog_category($blog_id, 2);
  }
  
  return $blog;
}

function __blog_category($blog_id, $cat_type=1){
  global $database;
  
  $res = $database->db_query("SELECT c.* FROM categories c INNER JOIN blog_cats bc ON c.`cat_id`=bc.`bc_cat_id` WHERE bc.`bc_blog_id`=%d AND c.`cat_type`=%d;", $blog_id, $cat_type);
  
  $aCat = array();
  while ($cat = $database->db_fetch_assoc($res)){
    $aCat[$cat['cat_id']] = $cat;
  }
  
  return $aCat;
}

?>